package com.agency.utilDao;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.agency.entity.Authentication;
import com.agency.entity.User;
import com.agency.util.HibernateUtil;

public class UtilDao {

	public void addUser(User user, Authentication authentication) {
    	System.out.println("=== user: " + user.getEmail() + " " + user.getFirstName() + " "+ user.getFirstName());
        Transaction trns = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            trns = session.beginTransaction();
            session.save(user);
            session.save(authentication);
            session.getTransaction().commit();
        } catch (RuntimeException e) {
            if (trns != null) {
                trns.rollback();
            }
            e.printStackTrace();
        } finally {
            session.flush();
            session.close();
        }
    }
}
